#include <iostream>
//奇异递归   实现多态是没有成本的

template<typename T>
class Animal
{
public:
    void speak()
    {
        ((T*)this)->speak();
    }
};

class Dog : public Animal<Dog>
{
public:
    void speak()
    {
        std::cout<<"汪汪汪"<<std::endl;
    }
};

class Cat : public Animal<Cat>
{
public:
    void speak()
    {
        std::cout<<"喵喵喵"<<std::endl;
    }
};
template<typename T>
void Speak(Animal<T> &a)
{
    a.speak();
}


int main()
{
    Dog d;
    Cat c;
    Speak(d);
    Speak(c);
    return 0;
}